﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Issues.IssueQuestTasks.ChangeSettlementOwnerTask
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Issues.IssueQuestTasks
{
  public class ChangeSettlementOwnerTask : QuestTaskBase
  {
    [SaveableField(30)]
    private readonly Settlement _settlement;
    [SaveableField(31)]
    private readonly Hero _newOwner;

    internal static void AutoGeneratedStaticCollectObjectsChangeSettlementOwnerTask(
      object o,
      List<object> collectedObjects)
    {
      ((QuestTaskBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._settlement);
      collectedObjects.Add((object) this._newOwner);
    }

    internal static object AutoGeneratedGetMemberValue_settlement(object o)
    {
      return (object) ((ChangeSettlementOwnerTask) o)._settlement;
    }

    internal static object AutoGeneratedGetMemberValue_newOwner(object o)
    {
      return (object) ((ChangeSettlementOwnerTask) o)._newOwner;
    }

    public ChangeSettlementOwnerTask(
      Settlement settlement,
      Hero newOwner,
      Action onSucceededAction,
      Action onFailedAction,
      Action onCanceledAction,
      DialogFlow dialogFlow = null)
      : base(dialogFlow, onSucceededAction, onFailedAction, onCanceledAction)
    {
      this._settlement = settlement;
      this._newOwner = newOwner;
    }

    public void OnSettlementOwnerChanged(
      Settlement settlement,
      bool openToClaim,
      Hero newOwner,
      Hero oldOwner,
      Hero capturerHero,
      ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
    {
      if (this._settlement != settlement || this._newOwner != newOwner)
        return;
      this.Finish(QuestTaskBase.FinishStates.Success);
    }

    public override void SetReferences()
    {
      CampaignEvents.OnSettlementOwnerChangedEvent.AddNonSerializedListener((object) this, new Action<Settlement, bool, Hero, Hero, Hero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail>(this.OnSettlementOwnerChanged));
    }
  }
}
